package com.ltmall.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.ltmall.api.bean.*;
import com.ltmall.api.bean.Collection;
import com.ltmall.api.comm.Path;
import com.ltmall.api.comm.TimeUtil;
import com.ltmall.api.entity.JsonAccount;
import com.ltmall.api.entity.ThJsonClientInfo;
import com.ltmall.api.enums.AccountPointChangeEnum;
import com.ltmall.api.manager.*;
import com.ltmall.api.news.NewsCenter;
import com.ltmall.api.parse.CollectionParse;
import com.ltmall.api.parse.bean.GoodsCollection;
import com.ltmall.api.redis.RedisUtil;
import com.ltmall.api.secret.Secret;
import com.ltmall.api.util.HttpRequestUtil;
import com.ltmall.api.util.PageUtil;
import com.ltmall.api.util.RemoteUtil;
import com.ltmall.api.weixin.pay.Constants;
import com.ltmall.api.weixin.util.TemplateMessageUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;

@Controller
public class AccountController {

    /**
     * 用户账号控制器
     */
    private AccountManager accountManager;

    private NewsManager newsManager;

    private WalletManager walletManager;

    private SubUnderwritingManager subUnderwritingManager;

    private ClientAccountManager clientAccountManager;

    private JSONObject authInfo;

    public SubUnderwritingManager getSubUnderwritingManager() {
        return subUnderwritingManager;
    }

    public void setSubUnderwritingManager(SubUnderwritingManager subUnderwritingManager) {
        this.subUnderwritingManager = subUnderwritingManager;
    }

    public WalletManager getWalletManager() {
        return walletManager;
    }

    public void setWalletManager(WalletManager walletManager) {
        this.walletManager = walletManager;
    }

    public NewsManager getNewsManager() {
        return newsManager;
    }

    public void setNewsManager(NewsManager newsManager) {
        this.newsManager = newsManager;
    }

    public AccountManager getAccountManager() {
        return accountManager;
    }

    public void setAccountManager(AccountManager accountManager) {
        this.accountManager = accountManager;
    }

    private Logger logger = LogManager.getLogger(AccountController.class);

    boolean opTag, valiTag;

    //	微信签名
    public void wechatSignature(HttpServletRequest request, HttpServletResponse response) {
        String accessToken = RedisUtil.getAccessToken();
        JSONObject ticketJson = HttpRequestUtil.sendGet(
                "https://api.weixin.qq.com/cgi-bin/ticket/getticket", "access_token=" + accessToken
                        + "&type=jsapi");

        if (ticketJson.containsKey("errcode")) {
            int errcode = (Integer) ticketJson.get("errcode");
            if (errcode > 0) {
                logger.warn("getticket接口出错了：" + errcode);
                // 清空一下缓存的token
                if (errcode == 40001) {
                    accessToken = RedisUtil.refreshAccessToken();
                    ticketJson = HttpRequestUtil.sendGet(
                            "https://api.weixin.qq.com/cgi-bin/ticket/getticket", "access_token="
                                    + accessToken
                                    + "&type=jsapi");
                }
            }
        }

        Map<String, String> ret = new HashMap<>(5);
        String url = request.getParameter("url");
        String jsapiTicket = ticketJson.get("ticket").toString();
        String timestamp = Long.toString(System.currentTimeMillis() / 1000);
        String noncestr = UUID.randomUUID().toString();
        String signature = "";

        String string1 = "jsapi_ticket=" + jsapiTicket + "&noncestr=" + noncestr + "&timestamp="
                + timestamp + "&url=" + url;

        try {
            MessageDigest crypt = MessageDigest.getInstance("SHA-1");
            crypt.reset();
            crypt.update(string1.getBytes("UTF-8"));
            signature = byteToHex(crypt.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        ret.put("appId", Constants.OA_APP_ID);
        ret.put("nonceStr", noncestr);
        ret.put("timestamp", timestamp);
        ret.put("signature", signature);
        ret.put("acToken", accessToken);

        RemoteUtil.response(response, ret, 1, "返回成功");

    }

    /**
     * 字节转换成16进制
     *
     * @param hash
     * @return 16进制字符串
     */
    private String byteToHex(final byte[] hash) {
        Formatter formatter = new Formatter();
        for (byte b : hash) {
            formatter.format("%02x", b);
        }
        String result = formatter.toString();
        formatter.close();
        return result;
    }

    /**
     * 获取授权access_token
     *
     * @param request
     * @param response
     * @param code
     */
    public void getAccessToken(HttpServletRequest request, HttpServletResponse response, String code) {
        String appid = Constants.appIDGet();
        String appSecret = Constants.appSecretGet();

        String url = "https://api.weixin.qq.com/sns/oauth2/access_token";
        String param = "appid=";
        param += appid + "&secret=";
        param += appSecret + "&code=";
        param += code + "&grant_type=authorization_code";
        authInfo = HttpRequestUtil.sendGet(url, param);
        System.out.println("getAccessToken authInfo:" + authInfo);
        try {
            System.out.println(authInfo.get("openid"));
            RedisUtil.oAuthAccessTokenSet(authInfo.getString("openid"),
                    authInfo.getString("access_token"), authInfo.getInteger("expires_in"));
            RedisUtil.jedisSet(authInfo.getString("openid") + "refresh_token",
                    authInfo.getString("refresh_token"));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    /**
     * 获取用户微信信息
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void getUserWechatInfo(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("getUserWechatInfo begin:" + System.currentTimeMillis());
        String url = "https://api.weixin.qq.com/sns/userinfo";
        String param = "access_token=";
        String openid = request.getParameter("openid");
        String accessToken = RedisUtil.oAuthAccessTokenGet(openid);
        if ("error".equals(accessToken)) {
            wechatAuth(request, response);
        }
        param += accessToken + "&openid=";
        param += openid + "&lang=zh_CN";

        JSONObject userWechatInfo = HttpRequestUtil.sendGet(url, param);

        if (userWechatInfo.get("errcode") != null) {
            // wechatAuth(request, response);
            RemoteUtil.response(response, userWechatInfo, 0, "获取信息失败");
        } else {
            userWechatInfo.put("openid", request.getParameter("openid"));
            System.out.println("getUserWechatInfo end:" + System.currentTimeMillis());
            System.out.println("getUserWechatInfo userWechatInfo: " + userWechatInfo);
            RemoteUtil.response(response, userWechatInfo, 1, "返回成功");
        }
    }

    public void getUserInfo(HttpServletRequest request, HttpServletResponse response) {
        final String openId = request.getParameter("openId");
        ClientConfig config = new ClientConfig();
        ThClientPlatforms thClientPlatforms = accountManager.checkUserExistByOpenID(openId);
        if (thClientPlatforms == null) {
            //用户不存在情况，帮用户后台进行注册登录操作
            thClientPlatforms = new ThClientPlatforms();
            thClientPlatforms.setOpenId(openId);
            String url = "https://api.weixin.qq.com/sns/userinfo";
            String param = "access_token=";
            String accessToken = RedisUtil.oAuthAccessTokenGet(openId);
            if ("error".equals(accessToken)) {
                RemoteUtil.response(response, null, -1, "获取用户accessToken发生错误");
                return;
            }
            param += accessToken + "&openid=";
            param += openId + "&lang=zh_CN";
            JSONObject userWechatInfo = HttpRequestUtil.sendGet(url, param);
            System.out.println(userWechatInfo);
            if (userWechatInfo.get("errcode") != null) {
                RemoteUtil.response(response, userWechatInfo, 0, "获取信息失败");
            } else {
                userWechatInfo.put("openid", request.getParameter("openid"));
                ClientInfo clientInfo = new ClientInfo();
                clientInfo.setCity(userWechatInfo.getString("city"));
                clientInfo.setCounty(userWechatInfo.getString("country"));
                clientInfo.setLevelId(0);
                clientInfo.setName(userWechatInfo.getString("nickname"));
                clientInfo.setOpTime(System.currentTimeMillis());
                clientInfo.setPhoto(userWechatInfo.getString("headimgurl"));
                clientInfo.setProvince(userWechatInfo.getString("province"));
                clientInfo.setSex(userWechatInfo.getInteger("sex"));
                config = register(clientInfo, thClientPlatforms);

                if (request.getParameterMap().containsKey("underwriterID") && config != null) {
                    String underwriterID = request.getParameter("underwriterID");
                    addSubUnderwriterFans(config.getUserID(), underwriterID);
                }

                if (config != null) {
                    JsonAccount jsonAccount = login(config, clientInfo);
                    RemoteUtil.response(response, jsonAccount, 0, "返回成功");
                }
            }
            return;
        } else {
            //用户存在情况，帮用户后台进行登录操作
            int userId = thClientPlatforms.getUserId();
            ClientInfo info = accountManager.getInfo(userId);
            config = accountManager.getConfig(userId);
            JsonAccount jaAccount = login(config, info);
            RemoteUtil.response(response, jaAccount, 1, "返回成功");
        }
    }

    public JsonAccount login(ClientConfig config, ClientInfo info) {
        ClientAccount account = accountManager.getAccount(null, config.getUserID());
        String token = Secret.TokenGenerate(account.getPhone());
        // 修改token
        accountManager.updateToken(account.getUserID(), token);
        if (account != null) {
            // 如果没有乡币账户，则在登录的时候自动创建
            // ThHcWallet wallet = walletManager.getWalletByUser(account.getUserID());
            Boolean isBoolean = walletManager.isHaveWalletByUser(account.getUserID());
            if (!isBoolean) {
                ThHcWallet hcWallet = new ThHcWallet();
                hcWallet.setAvaileAmounts(0);
                hcWallet.setFreezonAmounts(0);
                hcWallet.setUserId(config.getUserID());
                hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
                walletManager.hcWalletCreate(hcWallet);
            }
        }
        JsonAccount ja = new JsonAccount();
        ja.setUserID(config.getUserID());
        ja.setUserToken(token);
        ja.setUserPass(config.getUserPass());

        ja.setProvince(info.getProvince());
        ja.setCity(info.getCity());
        ja.setCounty(info.getCounty());
        ja.setPhone(account.getPhone());
        ja.setUserName(info.getName());
        ja.setIcon(info.getPhoto());
        ja.setLinkedDirectSupplyId(info.getLinkedDirectSupplyId());
        return ja;

    }

    public void getWechatToken(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("code") == null) {
            RemoteUtil.response(response, null, -1, "code不能为空");
            return;
        }

        String code = request.getParameter("code");
        String page = "";
        getAccessToken(request, response, code);
        System.out.println("getWechatToken autoInfo:" + authInfo);
        Map mapArr = new HashMap();
        mapArr = parseQueryString(request.getQueryString());
        String[] arr = java.net.URLDecoder.decode(mapArr.get("page").toString()).split("[?]");
        System.out.println("getWechatToken arr:" + arr);
        if (arr.length > 1) {
            page += arr[0];
            page += "?openid=" + authInfo.get("openid");
            if (arr[1].split("#")[0] != "") {
                page += "&";
            }
            page += arr[1];
        } else {
            if (arr[0].split("#").length > 1) {
                page += arr[0].split("#")[0];
                page += "?openid=" + authInfo.get("openid");
                page += "#";
                page += arr[0].split("#")[1];
            } else {
                page += arr[0];
                page += "?openid=" + authInfo.get("openid");
            }
        }
        page = page.replace("&#", "#");
        System.out.println("getWechatToken page:" + page);
        try {
            response.sendRedirect(page);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    // 微信授权
    public void wechatAuth(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("code") != null) {
            String code = request.getParameter("code");
            String page = "";

            getAccessToken(request, response, code);
            System.out.println(authInfo);
            Map mapArr = new HashMap();
            mapArr = parseQueryString(request.getQueryString());
            String[] arr = java.net.URLDecoder.decode(mapArr.get("page").toString()).split("[?]");

            if (arr.length > 1) {
                page += arr[0];
                page += "?openid=" + authInfo.get("openid");
                page += "&token=" + authInfo.get("access_token");
                if (arr[1].split("#")[0] != "")
                    page += "&";
                page += arr[1];
            } else {
                if (arr[0].split("#").length > 1) {
                    page += arr[0].split("#")[0];
                    page += "?openid=" + authInfo.get("openid");
                    page += "&token=" + authInfo.get("access_token");
                    page += "#";
                    page += arr[0].split("#")[1];
                } else {
                    page += arr[0];
                    page += "?openid=" + authInfo.get("openid");
                    page += "&token=" + authInfo.get("access_token");
                }
            }
            page = page.replace("&#", "#");

            try {
                response.sendRedirect(page);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            Map mapArr = parseQueryString(request.getQueryString());
            String page = mapArr.get("page").toString();
            String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
                    + Constants.OA_APP_ID + "&redirect_uri=";
            url += java.net.URLEncoder.encode(request.getRequestURL().toString()
                    + "?method=wechatAuth&page=" + page);
            url += "&response_type=code&scope=snsapi_base#wechat_redirect";
            System.out.println("WechatAuth url:" + url);
            try {
                response.sendRedirect(url);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return;
        }
    }

    /**
     * 微信静默授权
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void wechatSilentAuth(HttpServletRequest request, HttpServletResponse response) {
        if (request.getParameter("code") != null) {
            String code = request.getParameter("code");
            String page = "";

            getAccessToken(request, response, code);
            Map mapArr = new HashMap();
            mapArr = parseQueryString(request.getQueryString());
            String[] arr = java.net.URLDecoder.decode(mapArr.get("page").toString()).split("[?]");

            if (arr.length > 1) {
                page += arr[0];
                page += "?openid=" + authInfo.get("openid");
                page += "&token=" + authInfo.get("access_token");
                if (arr[1].split("#")[0] != "")
                    page += "&";
                page += arr[1];
            } else {
                if (arr[0].split("#").length > 1) {
                    page += arr[0].split("#")[0];
                    page += "?openid=" + authInfo.get("openid");
                    page += "&token=" + authInfo.get("access_token");
                    page += "#";
                    page += arr[0].split("#")[1];
                } else {
                    page += arr[0];
                    page += "?openid=" + authInfo.get("openid");
                }
            }
            page = page.replace("&#", "#");

            try {
                response.sendRedirect(page);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            Map mapArr = parseQueryString(request.getQueryString());
            String page = mapArr.get("page").toString();
            String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
                    + Constants.OA_APP_ID + "&redirect_uri=";
            url += java.net.URLEncoder.encode(request.getRequestURL().toString()
                    + "?method=wechatAuth&page=" + page);
            url += "&response_type=code&scope=snsapi_base#wechat_redirect";
            try {
                response.sendRedirect(url);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return;
        }
    }

    /**
     * 将路径解析成键值对数组
     *
     * @param str 路径字符串
     * @return 路径Map
     */
    public Map<String, String> parseQueryString(String str) {
        String[] paramArr = str.split("&");
        Map mapArr = new HashMap();
        for (String param : paramArr) {
            String[] arr = param.split("=");
            if (arr.length > 1) {
                mapArr.put(arr[0], arr[1]);
            }
        }
        return mapArr;
    }

    /**
     * 注册（内部方法）
     *
     * @param clientInfo
     * @param platform
     * @return ClientConfig
     */
    public ClientConfig register(ClientInfo clientInfo, ThClientPlatforms platform) {
        ClientAccount account = new ClientAccount();
        // 默认账号，APP登录时要判断为0不可登录
        account.setPhone(Integer.toString(0));
        account.setPass(Secret.passGenerate(account.getUserID(), account.getPhone()));
        // 设置账号为未绑定手机状态
        account.setBindState(1);

        // ThClientPlatforms platform = new ThClientPlatforms();
        String subUnderwriterId = null;

        opTag = accountManager.addClientAccount(account);
        if (opTag) {
            try {
                ClientConfig config = addConfigAndInfo(account, clientInfo);
                // 添加平台信息
                addPlatform(account, platform);
                // 添加钱包帐号
                addWallet(config.getUserID());
                // 添加礼品卡
                createCoupon(config.getUserID());
                // 添加礼品卡账户
                addGiftCardCount(config.getUserID());
                // 添加乡币账户
                ThHcWallet hcWallet = new ThHcWallet();
                hcWallet.setAvaileAmounts(0);
                hcWallet.setFreezonAmounts(0);
                hcWallet.setUserId(config.getUserID());
                hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
                walletManager.hcWalletCreate(hcWallet);
                // 添加分销人粉丝
                addSubUnderwriterFans(config.getUserID(), subUnderwriterId);
                return config;

            } catch (Exception e) {
                e.printStackTrace();
                logger.warn("注册失败：" + e.getMessage());
                return null;
            }
        }
        return null;

    }

    /**
     * 用户注册接口
     *
     * @param request
     * @param response
     */
    public void register(HttpServletRequest request, HttpServletResponse response) {
        ClientAccount account = (ClientAccount) RemoteUtil.request(request, new ClientAccount());
        ClientInfo info = (ClientInfo) RemoteUtil.request(request, new ClientInfo());

        // 手机号已经被使用了
        if (accountManager.isPhoneUsed(account.getPhone())) {
            RemoteUtil.response(response, null, 0, "手机号已经注册");
            return;
        }
        opTag = accountManager.addClientAccount(account);
        if (opTag) {
            ClientConfig config = addConfigAndInfo(account, info);
            addHuanxinRegister(config.getUserID(), config.getUserPass());

            //添加钱包帐号
            addWallet(config.getUserID());
            //添加礼品卡
            createCoupon(config.getUserID());
            //添加礼品卡账户
            addGiftCardCount(config.getUserID());
            // 添加乡币账户
            ThHcWallet hcWallet = new ThHcWallet();
            hcWallet.setAvaileAmounts(0);
            hcWallet.setFreezonAmounts(0);
            hcWallet.setUserId(config.getUserID());
            hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
            walletManager.hcWalletCreate(hcWallet);
            RemoteUtil.response(response, config, 1, "操作成功");
            return;
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    /**
     * 创建礼品卡帐号
     *
     * @param userID
     * @return
     * @throws
     */
    public void addGiftCardCount(int userID) {
        WalletGiftCardCount gCardCount = new WalletGiftCardCount();
        gCardCount.setUserID(userID);
        gCardCount.setMoney(0);
        walletManager.addGiftCardCount(gCardCount);
    }

    /**
     * 创建钱包
     *
     * @param userID 用户编号
     */
    public void addWallet(int userID) {
        WalletCash wCash = new WalletCash();
        wCash.setUserID(userID);
        wCash.setMoney(0);
        walletManager.addWalletCash(wCash);
    }

    /**
     * 创建代金券
     *
     * @param userID 用户编号
     */
    public void createCoupon(int userID) {
        // 一共送五张代金券； 两张5元的，两张10元的，一张20元的
        int[] moneyArr = {5, 5, 10, 10, 20};
        long startTime = System.currentTimeMillis();
        long endTime = TimeUtil.getEndTime(startTime, 2, 6);
        // 生成五张代金券
        for (int i = 0; i < moneyArr.length; i++) {
            int money = moneyArr[i];
            addCoupon(userID, money, startTime, endTime);
        }

        // 添加代金券消息
        couponNews(userID);
    }

    /**
     * 创建10元的代金券
     *
     * @param userID
     * @param money
     * @param startTime
     * @param endTime
     */
    public void addCoupon(int userID, int money, long startTime, long endTime) {
        WalletCoupon coupon = new WalletCoupon();
        coupon.setUserID(userID);
        coupon.setMoney(money);
        coupon.setStartTime(startTime);
        coupon.setEndTime(endTime);
        coupon.setValid(1);
        walletManager.addWalletCoupon(coupon);
    }

    ;

    /**
     * 给分销人添加粉丝
     *
     * @param userId
     * @param subUnderwriterIdStr
     */
    public void addSubUnderwriterFans(int userId, String subUnderwriterIdStr) {

        if (subUnderwriterIdStr == null || subUnderwriterIdStr.equals("")) {
            return;
        }

        //【1】查询分销人信息，分销人信息不存在则返回
        int subUnderwriterId = Integer.parseInt(subUnderwriterIdStr);
        ThSubUnderwriters subUnderwriter = subUnderwritingManager.subUnderwriterGet(subUnderwriterId);
        if (subUnderwriter == null) {
            return;
        }

        //【2】为分销人添加粉丝
        ThSubUnderwriterFans fans = new ThSubUnderwriterFans();
        fans.setSubUnderwriterId(subUnderwriterId);
        fans.setFansId(userId);
        subUnderwritingManager.subUnderwriterFansAdd(fans);

        //【3】更新该用户的积分（一个粉丝赠送一个积分）
        clientAccountManager.updateAccountPoint(subUnderwriterId, 1, AccountPointChangeEnum.POINT_UP);

        //【4】 判断该分销人成功申请为分销用户是否满一个月
        //【4.1】不满一个月则直接返回
        long interval = 30 * 24 * 60 * 60 * 1000l;
        long time = System.currentTimeMillis() - interval;
        if (subUnderwriter.getCreatedAt().getTime() < time) {
            return;
        }

        //【4.2】满一个月，则根据粉丝数更新分销人等级
        int fansCount = subUnderwritingManager.subUnderwriterFansCount(subUnderwriterId);
        int levelId = 0;
        if (fansCount >= 1000) {
            levelId = 3;
        } else if (fansCount >= 300) {
            levelId = 2;
        } else if (fansCount >= 50) {
            levelId = 1;
        }

        //升级后的等级应该大于该用户当前的等级
        ClientInfo subUnderwriterInfo = accountManager.getInfo(subUnderwriterId);
        if (levelId > subUnderwriterInfo.getLevelId()) {
            accountManager.updateLevel(subUnderwriterId, levelId);
            //推送用户等级升级消息
            ThClientPlatforms clientPlatform = accountManager
                    .getClientPlatformByUserId(subUnderwriterId);
            if (clientPlatform != null) {
                ThUserLevels level = accountManager.userLevelGet(levelId);
                TemplateMessageUtil.sendLevelUpMessage(clientPlatform.getOpenId(),
                        subUnderwriterInfo.getName(), level.getTitle());
            }
        }

    }

    /**
     * 代金券消息
     *
     * @param userID 用户编号
     */
    public void couponNews(int userID) {
        int typeA = 1;
        String typeB = "B";
        String title = "代金券";
        String content = "初次登录，系统赠送您几张代金券，记得在购物的时候使用哦";
        String picture = null;
        String param = null;
        NewsCenter.news(userID, typeA, typeB, title, content, picture, param, newsManager, true);
    }

    /**
     * 添加初次登录消息
     *
     * @param userID 用户编号
     */
    public void addRegisterNews(int userID) {
        int typeA = 1;
        String typeB = "A";
        String title = "欢迎注册";
        String content = "欢迎使用乡味汇平台,祝您愉快~~~";
        String picture = null;
        String param = null;
        NewsCenter.news(userID, typeA, typeB, title, content, picture, param, newsManager, true);
    }

    /**
     * 操作成功添加环信帐号
     *
     * @param userID   用户编号
     * @param userPass 用户环信密码
     */
    public void addHuanxinRegister(int userID, String userPass) {
        // HXRegister.register(userID + "", userPass);
        // 添加消息
        // addRegisterNews(userID);
    }

    /**
     * 添加配置文件和个人信息文件
     *
     * @param account clientAccount对象
     * @param info    clientInfo对象
     * @return ClientConfig
     */
    public ClientConfig addConfigAndInfo(ClientAccount account, ClientInfo info) {
        ClientConfig config = new ClientConfig();
        config.setUserID(account.getUserID());
        config.setUserToken(Secret.TokenGenerate(account.getPhone()));
        config.setUserPass(Secret.passGenerate(account.getUserID(), account.getPhone()));

        info.setUserID(account.getUserID());
        accountManager.initConfigAndInfo(config, info);
        return config;
    }

    public void feedback(HttpServletRequest request, HttpServletResponse response) {
        Feedback feedback = (Feedback) RemoteUtil.request(request, new Feedback());
        opTag = accountManager.addFeedback(feedback);
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    /**
     * 用户登录
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void login(HttpServletRequest request, HttpServletResponse response) {
        String phone = request.getParameter("phone");
        String pass = request.getParameter("pass");
        opTag = accountManager.phoneLogin(phone, pass);
        // 验证成功
        if (opTag) {
            ClientAccount account = accountManager.getAccount(phone, 0);
            // 产生新的token
            String token = Secret.TokenGenerate(account.getPhone());
            // 修改token
            accountManager.updateToken(account.getUserID(), token);
            ClientConfig config = accountManager.getConfig(account.getUserID());

            // 如果没有乡币账户，则在登录的时候自动创建
            ThHcWallet wallet = walletManager.getWalletByUser(account.getUserID());
            if (wallet == null) {
                ThHcWallet hcWallet = new ThHcWallet();
                hcWallet.setAvaileAmounts(0);
                hcWallet.setFreezonAmounts(0);
                hcWallet.setUserId(config.getUserID());
                hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
                walletManager.hcWalletCreate(hcWallet);
            }

            // 获取个人信息
            ClientInfo info = accountManager.getInfo(account.getUserID());

            JsonAccount ja = new JsonAccount();
            ja.setUserID(config.getUserID());
            ja.setUserToken(config.getUserToken());
            ja.setUserPass(config.getUserPass());

            ja.setProvince(info.getProvince());
            ja.setCity(info.getCity());
            // 县
            ja.setCounty(info.getCounty());
            // 返回手机号
            ja.setPhone(account.getPhone());

            RemoteUtil.response(response, ja, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    /**
     * 修改个人信息
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void editInfo(HttpServletRequest request, HttpServletResponse response) {
        ClientInfo info = (ClientInfo) RemoteUtil.request(request, new ClientInfo());
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(info.getUserID(), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }
        opTag = accountManager.updateInfo(info.getUserID(), info.getName(), info.getSex());
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    /**
     * 修改籍贯
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void editHome(HttpServletRequest request, HttpServletResponse response) {
        ClientInfo info = (ClientInfo) RemoteUtil.request(request, new ClientInfo());
        opTag = accountManager.editHome(info.getUserID(), info.getProvince(), info.getCity(),
                info.getCounty());
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }

        RemoteUtil.response(response, null, -1, "操作失败");
    }

    /**
     * 修改籍贯
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void editDirectSupplyId(HttpServletRequest request, HttpServletResponse response) {
        ClientInfo info = (ClientInfo) RemoteUtil.request(request, new ClientInfo());
        opTag = accountManager.editDirectSupplyId(info.getUserID(), info.getLinkedDirectSupplyId() + "");
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }

        RemoteUtil.response(response, null, -1, "操作失败");
    }

    /**
     * 获取个人信息
     *
     * @param request  请求对象
     * @param response 响应对象
     */
    public void getInfo(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("getInfo begin:" + System.currentTimeMillis());
        String userID = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        ClientInfo info = accountManager.getInfo(Integer.parseInt(userID));
        if (info == null) {
            RemoteUtil.response(response, null, -1, "帐号不存在");
            return;
        }
        valiTag = accountManager.validate(info.getUserID(), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        ThJsonClientInfo jsonInfo = new ThJsonClientInfo();
        jsonInfo.setUserID(info.getUserID());
        jsonInfo.setName(info.getName());
        jsonInfo.setSex(info.getSex());
        jsonInfo.setProvince(info.getProvince());
        jsonInfo.setCity(info.getCity());
        jsonInfo.setCounty(info.getCounty());
        jsonInfo.setLevelId(info.getLevelId());
        jsonInfo.setLinkedDirectSupplyId(info.getLinkedDirectSupplyId());

        // 返回图片的真实路径
        String photoURL = Path.nginx_server_dir_client + Path.PHOTO + File.separator
                + info.getPhoto();
        jsonInfo.setPhoto(photoURL);

        Object[] obj = subUnderwritingManager.referrerInfo(jsonInfo.getUserID());
        if (obj != null) {
            jsonInfo.setReferrerName(obj[1] == null ? null : obj[1].toString());
        }
        System.out.println("getInfo end:" + System.currentTimeMillis());
        RemoteUtil.response(response, jsonInfo, 1, "返回成功");
    }

    /**
     * 修改个人头像
     *
     * @param
     */
    public void updatePhoto(HttpServletRequest request, HttpServletResponse response) {
        String userID = request.getParameter("userID");
        String photoName = request.getParameter("photoName");

        System.out.println("--userID---" + userID);
        System.out.println("--photoName---" + photoName);

        if (userID == null || userID.equals("") || photoName == null || photoName.equals("")) {
            System.out.println("头像修改失败");
            RemoteUtil.response(response, null, -1, "操作失败");
            return;
        }

        accountManager.updatePhoto(Integer.parseInt(userID), photoName);
        String photoURL = Path.nginx_server_dir_client + Path.PHOTO + File.separator + photoName;
        RemoteUtil.response(response, photoURL, 1, "操作成功");
    }

    /**
     * 添加收获地址
     *
     * @param
     */
    public void addAddr(HttpServletRequest request, HttpServletResponse response) {
        DeliveryAddr addr = (DeliveryAddr) RemoteUtil.request(request, new DeliveryAddr());
        opTag = accountManager.addDelevery(addr);
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    // 获取收获地址
    public void addrList(HttpServletRequest request, HttpServletResponse response) {
        String userID = request.getParameter("userID");

        String isDefault = request.getParameter("isDefault");
        int number = 0;
        if (isDefault != null) {
            number = 1;
        }

        List<DeliveryAddr> addrList = accountManager.getDelivery(Integer.parseInt(userID), number);
        RemoteUtil.response(response, addrList, 1, "返回成功");
    }

    // 获取收获地址
    public void editAddr(HttpServletRequest request, HttpServletResponse response) {
        DeliveryAddr addr = (DeliveryAddr) RemoteUtil.request(request, new DeliveryAddr());
        String strDefault = request.getParameter("isDefault");
        if (strDefault.equals("true") || strDefault.equals("1")) {
            addr.setIsDefault(1);
        } else {
            addr.setIsDefault(0);
        }
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(addr.getUserID(), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        opTag = accountManager.updateDelevery(addr.getAddrID(), addr.getUserID(), addr.getName(),
                addr.getPhone(), addr.getAddress(), addr.getProvince(), addr.getCity(),
                addr.getCounty(), addr.getIsDefault());
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    // 删除收获地址
    public void delAddr(HttpServletRequest request, HttpServletResponse response) {
        String addrID = request.getParameter("addrID");

        String userID = request.getParameter("userID");
        String userToken = request.getParameter("userToken");

        valiTag = accountManager.validate(Integer.parseInt(userID), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        opTag = accountManager.deleDelivery(Integer.parseInt(addrID));
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    // 修改密码
    public void updatePass(HttpServletRequest request, HttpServletResponse response) {
        String userID = request.getParameter("userID");
        String newPass = request.getParameter("newPass");
        String oldPass = request.getParameter("oldPass");

        ClientAccount account = accountManager.getAccount(null, Integer.parseInt(userID));
        if (!account.getPass().equals(oldPass)) {
            RemoteUtil.response(response, null, -2, "密码不正确");
            return;
        }
        opTag = accountManager.updatePass(Integer.parseInt(userID), newPass);
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    // 忘记密码
    public void forgetPass(HttpServletRequest request, HttpServletResponse response) {
        String phone = request.getParameter("phone");
        String pass = request.getParameter("pass");
        ClientAccount account = accountManager.getAccount(phone, 0);

        if (account == null) {
            RemoteUtil.response(response, null, 0, "该手机号码未注册");
            return;
        }
        opTag = accountManager.updatePass(account.getUserID(), pass);
        if (opTag) {
            RemoteUtil.response(response, null, 1, "成功成功");
            return;
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    // 商家注册
    public void bussinessRegister(HttpServletRequest request, HttpServletResponse response) {
        BussinessInfo bInfo = (BussinessInfo) RemoteUtil.request(request, new BussinessInfo());
        if (bInfo == null) {
            System.out.print("AccountController:bussinessRegister() bInfo为空");
            RemoteUtil.response(response, null, -1, "操作失败");
        }
        opTag = accountManager.addBussinessInfo(bInfo);
        if (opTag) {
            BussinessAccount bAccount = new BussinessAccount();
            bAccount.setCompanyID(bInfo.getCompanyID());
            bAccount.setAccount(bInfo.getCompanyEmail());
            bAccount.setFrom(1);
            bAccount.setPassword("123456");
            RemoteUtil.response(response, null, 1, "操作成功");
            // 同时注册商家账号
            accountManager.addBussinessAccount(bAccount);
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    // 收藏
    public void collection(HttpServletRequest request, HttpServletResponse response) {
        Collection collection = (Collection) RemoteUtil.request(request, new Collection());
        opTag = accountManager.collection(collection);
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, 1, "操作失败");
        }
    }

    // //取消收藏
    // public void cancelCollection(HttpServletRequest request,
    // HttpServletResponse response){
    //
    // String collectionID = request.getParameter("collectionID");
    // String userID = request.getParameter("userID");
    // opTag =
    // accountManager.cancelCollection(Integer.parseInt(collectionID),Integer.parseInt(userID));
    // if(opTag){
    // RemoteUtil.response(response, null, 1, "操作成功");
    // }else{
    // RemoteUtil.response(response, null, -1, "操作失败");
    // }
    // }

    // 收藏列表
    public void collectionList(HttpServletRequest request, HttpServletResponse response) {
        Collection collection = (Collection) RemoteUtil.request(request, new Collection());
        String page = request.getParameter("page");
        List<?> list = accountManager.collectionList(collection.getUserID(),
                new PageUtil(Integer.parseInt(page)));
        List<GoodsCollection> returnList = CollectionParse.goodsParse(list);
        RemoteUtil.response(response, returnList, 1, "返回成功");
    }

    // 用openid检测用户是否存在
    public void checkUserExistsByOpenID(HttpServletRequest request, HttpServletResponse response) {
        String openID = request.getParameter("openId");
        ThClientPlatforms info = accountManager.checkUserExistByOpenID(openID);
        if (info != null) {
            RemoteUtil.response(response, info, 1, "返回成功");
        } else {
            RemoteUtil.response(response, null, 0, "不存在");
        }
    }

    public void addPlatform(ClientAccount account, ThClientPlatforms platform) {
        platform.setUserId(account.getUserID());
        // 平台编号1:微信
        platform.setPlatformId(1);
        accountManager.addClientPlatform(platform);
    }

    public void getAddrByAddrID(HttpServletRequest request, HttpServletResponse response) {
        String addrID = request.getParameter("addrID");
        DeliveryAddr addr = accountManager.getAddr(Integer.parseInt(addrID));
        Map<String, Object> addrMap = new HashMap<>();
        addrMap.put("addr", addr);
        RemoteUtil.response(response, addrMap, 1, "success");
    }

    public void registerByPlatform(HttpServletRequest request, HttpServletResponse response) {
        ClientAccount accountObj = new ClientAccount();
        ClientAccount account = (ClientAccount) RemoteUtil.request(request, accountObj);
        ClientInfo info = (ClientInfo) RemoteUtil.request(request, new ClientInfo());
        String subUnderwriterId = request.getParameter("subUnderwriterId");
        logger.info("新用户注册，用户名：" + info.getName());
        ThClientPlatforms platform = (ThClientPlatforms) RemoteUtil.request(request,
                new ThClientPlatforms());
        System.out.println("registerByPlatform accout:" + account.getUserID());
        // 默认账号，APP登录时要判断为0不可登录
        account.setPhone(Integer.toString('0'));
        account.setPass(Secret.passGenerate(account.getUserID(), account.getPhone()));
        // 设置账号为未绑定手机状态
        account.setBindState(1);
        // platformId = 1 : 微信
        platform.setPlatformId(1);
        platform.setCreatedAt(new java.util.Date(System.currentTimeMillis()));

        String accessToken = RedisUtil.getAccessToken();
        JSONObject userInfoJson = HttpRequestUtil.sendGet(
                "https://api.weixin.qq.com/cgi-bin/user/info", "access_token=" + accessToken
                        + "&openid=" + platform.getOpenId()
                        + "&lang=zh_CN");
        if (userInfoJson.containsKey("errcode")) {
            int errcode = (Integer) userInfoJson.get("errcode");
            if (errcode > 0) {
                logger.warn("验证openId错误：" + errcode);
                // 清空一下缓存的token
                if (errcode == 40001) {
                    accessToken = RedisUtil.refreshAccessToken();
                    userInfoJson = HttpRequestUtil.sendGet(
                            "https://api.weixin.qq.com/cgi-bin/user/info", "access_token="
                                    + accessToken + "&openid="
                                    + platform.getOpenId()
                                    + "&lang=zh_CN");
                    if (userInfoJson.containsKey("errcode")) {
                        logger.warn("验证openId连续错误：" + errcode);
                    }
                } else {
                    RemoteUtil.response(response, null, -1, "验证openid失败");
                    return;
                }
            }
        }

        opTag = accountManager.addClientAccount(account);
        if (opTag) {
            try {
                ClientConfig config = addConfigAndInfo(account, info);

                //默认成为我们的会员
                subUnderwritingManager.subUnderwriterAdd(config.getUserID());

                // 添加平台信息
                addPlatform(account, platform);
                // 添加钱包帐号
                addWallet(config.getUserID());
                // 添加礼品卡
                createCoupon(config.getUserID());
                // 添加礼品卡账户
                addGiftCardCount(config.getUserID());
                //添加乡币账户
                ThHcWallet hcWallet = new ThHcWallet();
                hcWallet.setAvaileAmounts(0);
                hcWallet.setFreezonAmounts(0);
                hcWallet.setUserId(config.getUserID());
                hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
                walletManager.hcWalletCreate(hcWallet);
                // 添加分销人粉丝
                addSubUnderwriterFans(config.getUserID(), subUnderwriterId);

                RemoteUtil.response(response, config, 1, "操作成功");
            } catch (Exception e) {
                e.printStackTrace();
                logger.warn("注册失败：" + e.getMessage());
                RemoteUtil.response(response, null, -1, "操作失败");
            }
        }
        RemoteUtil.response(response, null, -1, "操作失败");
    }

    // 用户登录
    public void loginByPlatformInfo(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("loginByPlatformInfo begin:" + System.currentTimeMillis());
        String accessToken = request.getParameter("token");
        String openID = request.getParameter("openID");
        String userID = request.getParameter("userID");
        // 跳过账号密码验证，直接验证token有效性

        if (true) {
            ClientAccount account = accountManager.getAccount(null, Integer.parseInt(userID));

            if (account != null) {
                // 产生新的token
                String token = Secret.TokenGenerate(account.getPhone());
                // 修改token
                accountManager.updateToken(account.getUserID(), token);
                ClientConfig config = accountManager.getConfig(account.getUserID());

                // 如果没有乡币账户，则在登录的时候自动创建
                ThHcWallet wallet = walletManager.getWalletByUser(account.getUserID());
                if (wallet == null) {
                    ThHcWallet hcWallet = new ThHcWallet();
                    hcWallet.setAvaileAmounts(0);
                    hcWallet.setFreezonAmounts(0);
                    hcWallet.setUserId(config.getUserID());
                    hcWallet.setCreatedAt(new java.util.Date(System.currentTimeMillis()));
                    walletManager.hcWalletCreate(hcWallet);
                }

                // 获取个人信息
                ClientInfo info = accountManager.getInfo(account.getUserID());

                JsonAccount ja = new JsonAccount();
                ja.setUserID(config.getUserID());
                ja.setUserToken(config.getUserToken());
                ja.setUserPass(config.getUserPass());

                ja.setProvince(info.getProvince());
                ja.setCity(info.getCity());
                ja.setCounty(info.getCounty());
                ja.setPhone(account.getPhone());
                ja.setUserName(info.getName());
                ja.setIcon(info.getPhoto());
                System.out.println("loginByPlatformInfo end:" + System.currentTimeMillis());
                RemoteUtil.response(response, ja, 1, "操作成功");
            } else {
                RemoteUtil.response(response, userID, -1, "用户不存在");
            }
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void getAccount(HttpServletRequest request, HttpServletResponse response) {
        ClientAccount account = null;
        try {
            boolean valiTag = accountManager
                    .validate(Integer.parseInt(request.getParameter("userID")),
                            request.getParameter("userToken"));
            if (!valiTag) {
                RemoteUtil.response(response, null, -100, "身份异常");
                return;
            }

            int userID = Integer.parseInt(request.getParameter("userID"));
            account = accountManager.getAccount(null, userID);
            if (account != null) {
                account.setPass(null);
                RemoteUtil.response(response, account, 1, "返回成功");
            } else {
                RemoteUtil.response(response, account, -1, "没有该用户");
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            RemoteUtil.response(response, account, -1, "操作失败");
        }
    }

    /**
     * @param clientAccountManager the clientAccountManager to set
     */
    public void setClientAccountManager(ClientAccountManager clientAccountManager) {
        this.clientAccountManager = clientAccountManager;
    }

    /**
     * 数据解析及重新组装
     *
     * @param data
     * @author tdl
     */
    private HashMap dataAnalysis(JSONObject data) throws Exception {
        HashMap<String, Object> response = new HashMap<>(1);
        HashMap<String, String> responseData = new HashMap<>(1);

        System.out.print(data);

        try {
            if (data.containsKey("errcode")) {
                String errCode = data.getString("errcode");
                String errMsg = data.getString("errmsg");

                System.out.print(errMsg);
                System.out.print(errCode);

                response.put("code", errCode);
                response.put("context", errMsg);
            } else {
                String openid = data.getString("openid");
                String sessionKey = data.getString("session_key");

                responseData.put("openId", openid);
                response.put("code", "1");
                response.put("openId", responseData);
                response.put("context", "SUCCESS");

                RedisUtil.oAuthAccessTokenSetForever(openid, sessionKey);
                //TODO: 去掉了refresh_token缓存写入是否会有问题
                //TODO: 缓存写失败没有异常处理
            }
            return response;
        } catch (Exception e) {
            throw e;
        }
    }

    /**
     * 小程序code换openid
     *
     * @param request
     * @param response
     * @return openid
     * @author tdl
     */
    public void weappAuth(HttpServletRequest request, HttpServletResponse response) {
        String code = request.getParameter("code");
        String appid = "wx64369bb1e924e6e2";
        String secret = "e7a0684c1f16b2a6fdbbd169ef2e8dc5";
        String api = "https://api.weixin.qq.com/sns/jscode2session";
        String params = String.format("appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", appid, secret, code);
        HashMap<String, String> data = new HashMap<>(1);
        System.out.print(params);

        authInfo = HttpRequestUtil.sendGet(api, params);

        try {
            if (authInfo.containsKey("errcode")) {
                String errCode = authInfo.getString("errcode");
                String errMsg = authInfo.getString("errmsg");

                System.out.print(errMsg);
                System.out.print(errCode);

                RemoteUtil.response(response, null, Integer.parseInt(errCode), errMsg);
            } else {
                String openid = authInfo.getString("openid");
                String sessionKey = authInfo.getString("session_key");

                data.put("openId", openid);
                RedisUtil.oAuthAccessTokenSetForever(openid, sessionKey);
                //TODO: 去掉了refresh_token缓存写入是否会有问题
                //TODO: 缓存写失败没有异常处理
                RemoteUtil.response(response, data, 1, "SUCCESS");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 创建/登录平台账户
     *
     * @param request
     * @param response
     * @author tdl
     */
    public void setPlatformAccount(HttpServletRequest request, HttpServletResponse response) {
        String openId = request.getParameter("openId");
        String city = request.getParameter("city");
        String county = request.getParameter("county");
        String nickname = request.getParameter("nickName");
        String province = request.getParameter("province");
        String gender = request.getParameter("gender");
        String avatarUrl = request.getParameter("avatarUrl");

        ClientConfig config = new ClientConfig();
        ThClientPlatforms thClientPlatforms = accountManager.checkUserExistByOpenID(openId);

        if (thClientPlatforms == null) {
            thClientPlatforms = new ThClientPlatforms();
            thClientPlatforms.setOpenId(openId);
            //TODO: 是否需要把选择的小区给设置进来
            ClientInfo clientInfo = new ClientInfo();
            clientInfo.setCity(city);
            clientInfo.setCounty(county);
            clientInfo.setLevelId(0);
            clientInfo.setName(nickname);
            clientInfo.setOpTime(System.currentTimeMillis());
            clientInfo.setPhoto(avatarUrl);
            clientInfo.setProvince(province);
            clientInfo.setSex(Integer.parseInt(gender));

            config = register(clientInfo, thClientPlatforms);

            if (config != null) {
                JsonAccount jsonAccount = login(config, clientInfo);
                RemoteUtil.response(response, jsonAccount, 0, "返回成功");
            }
        } else {
            //用户存在情况，帮用户后台进行登录操作
            int userId = thClientPlatforms.getUserId();
            ClientInfo info = accountManager.getInfo(userId);
            config = accountManager.getConfig(userId);
            JsonAccount jaAccount = login(config, info);
            RemoteUtil.response(response, jaAccount, 1, "返回成功");
        }
    }
}
